//network/api.js文件
import {
	getToken,
	removeToken
} from '@/utils/auth'
import store from '@/store/index.js'
import Request from './request.js'
import base from './baseUrl.js'
let request = new Request().http
console.log('token', store.state, 'token======')
console.log('token', store.state.token, 'token======')

function get(url, data, whetherData = true, hideLoading, header) {
	return request({
		url: url,
		method: 'GET',
		data: data,
		header: header,
		whetherData: whetherData,
		hideLoading: hideLoading,
	})
}

function post(url, data, whetherData = true, hideLoading, header) {
	return request({
		url: url,
		method: 'POST',
		data: data,
		header: header,
		whetherData: whetherData,
		hideLoading: hideLoading,
	})
}

function del(url, data, whetherData = true, hideLoading, header) {
	return request({
		url: url,
		method: 'DELETE',
		data: data,
		header: header,
		whetherData: whetherData,
		hideLoading: hideLoading,
	})
}

function put(url, data, whetherData = true, hideLoading, header) {
	return request({
		url: url,
		method: 'PUT',
		data: data,
		header: header,
		whetherData: whetherData,
		hideLoading: hideLoading,
	})
}

let api = {
	/*
	 *  ================上传（文件临时路径）=================
	 */
	uploadFilePromise(url, imageUrl, name = 'file') {
		return new Promise((resolve, reject) => {
			uni.uploadFile({
				url: base.baseUrl + url,
				filePath: imageUrl,
				name,
				header: {
					// Authorization: 'Bearer ' + store.state.token
					token: store.state.token
				},
				success: (res) => {
					resolve(JSON.parse(res.data))
				},
				fail(e) {
					reject(e)
				}
			});
		})
	},
	/*
	 *  ================上传（文件）=================
	 */
	uploadFilePromise_FILE(url, file, name = 'file') {
		return new Promise((resolve, reject) => {
			uni.uploadFile({
				url: base.baseUrl + url,
				file: file,
				name,
				header: {
					Authorization: 'Bearer ' + getToken()
				},
				success: (res) => {
					resolve(JSON.parse(res.data))
				},
				fail(e) {
					reject(e)
				}
			});
		})
	},
	// 发起支付
	requestPay(obj) {
		return new Promise((resolve, reject) => {
			uni.requestPayment({
				provider: obj.appId,
				timeStamp: obj.timeStamp,
				nonceStr: obj.nonceStr,
				package: obj.package,
				signType: obj.signType,
				paySign: obj.paySign,
				success: function(res) {
					console.log('success:' + JSON.stringify(res));
					resolve(JSON.stringify(res))
				},
				fail: function(err) {
					console.log('fail:' + JSON.stringify(err));
					reject(JSON.stringify(err))
				}
			})
		})
	},
	/*
	 *  ================api=================
	 */
	// 手机号验证码登录
	login: data => post('/api/login/mobileLogin', data),
	// 获得京津务工城市列表
	getJjCityList: data => post('/api/dict_data/getJjCityList', data),
	// 获取技能提升区县列表
	getSkillCityList: data => post('/api/dict_data/getSkillCityList', data),
	// 技能提升：轮播图列表
	getSideshowList: data => post('/api/skill.skill/getSideshowList', data),
	// 技能提升：首页开班信息
	getSkillClassIndexList: data => post('/api/skill.skill/getSkillClassIndexList', data),
	// 技能提升首页：机构列表
	getSkilllists: data => get('/api/skill.skill/lists', data),
	// 获取所有政策分类列表
	policydetail: data => get('/api/policy.policy/getPolicyCatList'),
	// 政策详情
	policydetailId: data => get('/api/policy.policy/detail', data),
	// 政策列表
	policylists: data => get('/api/policy.policy/lists', data),
	// 技能开班列表
	skillClassLists: data => get('/api/skill.skill/skillClassLists', data),
	// 技能开班详情
	skillClassDetail: data => get('/api/skill.skill/skillClassDetail', data),
	// 权益维护分类列表
	equitiesCatList: data => get('/api/equities.equities/equitiesCatList', data),
	// 权益维护详情
	equitiesdetail: data => get('/api/equities.equities/detail', data),
	// 权益维护列表
	equitieslists: data => get('/api/equities.equities/lists', data),
	// 所有零工超市点位
	supermarket: data => get('/api/supermarket.supermarket/list', data),
	// 零工测试
	supeindex: data => get('/api/job.job/index', data),
	// 公开招聘
	announcementLists: data => get('/api/job.job/announcementLists', data),
	// 公开招聘详情
	announcementDetail: data => get('/api/job.job/announcementDetail', data),
	// 最新零工/企业招聘
	joblists: data => get('/api/job.job/lists', data),
	// 最新零工、企业招聘的信息详情
	jobdetail: data => get('/api/job.job/detail', data),
	// 获取个人信息
	getinfo: data => post('/api/user/info', data),
	// 编辑用户信息
	setInfo: data => post('/api/user/setInfo', data),

	/* yixiashixinjiarude  */

	// 获取用户协议和隐私协议
	agreement: data => post('/api/user/agreement', data),
	//获取平台客服信息
	service: data => post('/api/user/service', data),
	//获取零工超市区县列表
	getSupermarketCityList: data => post('/api/dict_data/getSupermarketCityList', data),
	//获取薪资单位列表
	getSalaryUnitList: data => post('/api/dict_data/getSalaryUnitList', data),
	//获取服务类型列表
	getServiceTypeList: data => post('/api/dict_data/getServiceTypeList', data),
	//零工人才列表
	servicelists: data => get('/api/service.service/lists', data),
	//服务分类
	serviceCatList: data => post('/api/service.service/serviceCatList', data),
	//判断用户是否完善信息
	judgeMyMessage: data => post('/api/user/judgeMyMessage', data),
	//获取服务类型列表
	getServiceTypeList: data => post('/api/dict_data/getServiceTypeList', data),
	//用户服务列表
	myServiceLists: data => get('/api/user/myServiceLists', data),
	//发布服务
	serviceadd: data => post('/api/service.service/add', data),
	//职位详情
	servicedetail: data => get('/api/service.service/detail', data),
	//停止我的服务
	stopMyService: data => get('/api/user/stopMyService', data),
	//发布我的服务
	sentMyService: data => get('/api/user/sentMyService', data),
}
export default api